package com.gitee.wsl.common.chart.sample

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import androidx.core.graphics.withSave
import com.gitee.wsl.common.ui.draw.type.PanMode
import com.gitee.wsl.transform.format.Format


open class AbstractRadarChart( touchCheckAble: com.gitee.wsl.common.ui.api.TouchCheckAble? = null):XChart(touchCheckAble) {
    //半径
    override var radius = 0.0f

    //初始偏移角度
    var offsetAngle = 0f //180;


    //格式化线中点的标签显示
    var dotLabelFormatter: Format<Double>? = null

    //开放标签和线画笔让用户设置
    val labelPaint: Paint by lazy {
         Paint().apply {
            color = Color.BLACK
            textSize = 18f
            isAntiAlias = true
            textAlign = Paint.Align.CENTER
        }
    }
    
    val linePaint: Paint by lazy {
        Paint(Paint.ANTI_ALIAS_FLAG).apply {
            color = Color.rgb(180, 205, 230)
            style = Paint.Style.STROKE
            strokeWidth = 3f
        }
    }
    
    init {
       /* plotLegend.show()
        plotLegend.setType(ChartEnum.LegendType.ROW)
        plotLegend.setHorizontalAlign(ChartEnum.HorizontalAlign.CENTER)
        plotLegend.setVerticalAlign(ChartEnum.VerticalAlign.BOTTOM)
        plotLegend.showBox()
        plotLegend.hideBackground()*/
    }

    override fun calcPlotRange() {
        super.calcPlotRange()
        radius = (plotViewport.width/2f).coerceAtMost((plotViewport.height/2f))
    }


    override fun render(canvas: Canvas) {
        // TODO Auto-generated method stubcalcPlotRange
            if (isScrollEnabled) {
                canvas.withSave {
                    when (plotPanMode) {
                        PanMode.HORIZONTAL -> canvas.translate(translateXY[0], 0f)
                        PanMode.VERTICAL -> canvas.translate(0f, translateXY[1])
                        else -> canvas.translate(translateXY[0], translateXY[1])
                    }

                    //绘制图表
                    super.render(canvas)
                }
            } else {
                //绘制图表
                super.render(canvas)
            }

    }
    
}